package com.mf.gateway.filter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 通用异常过滤器
 * User: zhaoming
 * DateTime: 2017-12-24
 * To change this template use File | Settings | File Templates.
 **/
public class GenericErrorFilter extends ZuulFilter{

    private static Logger logger = LoggerFactory.getLogger(GenericErrorFilter.class);

    @Override
    public String filterType() {
        return "error";
    }

    @Override
    public int filterOrder() {
        return 10;
    }

    @Override
    public boolean shouldFilter() {
        return true;
    }

    @Override
    public Object run() {
        RequestContext requestContext = RequestContext.getCurrentContext();
        Throwable throwable = requestContext.getThrowable();
        logger.error("GenericErrorFilter : {}", throwable.getCause().getMessage());
        return null;
    }
}
